import os, time

file_size = 20 * 1024 * 1024


def get_file_name():
    file_name_list = list()
    for file in os.listdir(os.getcwd()):
        if os.path.splitext(file)[1] == '.log':
            file_name_list.append(os.getcwd().replace("\\", "/") + "/" + file)
    return file_name_list


def cut_file():
    fil_names = get_file_name()
    for file_name in fil_names:
        file_name_new = file_name
        count = 0
        eof = False
        with open(file_name_new, 'rb') as f_source:
            while True:
                f_source.seek(file_size * count, 0)
                chunk_data = f_source.read(file_size)
                if len(chunk_data) < file_size:
                    eof = True
                file_time = "{}_".format(count) + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
                with open("{0}_{1}".format(file_name, file_time + ".log"), 'wb') as f_dest:
                    print("creating {0} file".format(count))
                    f_dest.write(chunk_data)
                    count += 1
                if eof:
                    print("file cut finished\n")
                    break
    return


def main():
    cut_file()


if __name__ == '__main__':
    main()
